package gagak.framework.web.servlet.listener;

import gagak.framework.web.context.MvcApplicationContext;
import gagak.framework.web.context.MvcContextApplicationHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


/*
 * @program: ce
 * @description: web容器启动mvc框架环境加载器
 * @author: houhong
 * @create: 2022-11-23 15:39
 */
public final class ContextLoaderListener implements ServletContextListener {

    private static final Logger logger = LoggerFactory.getLogger(ContextLoaderListener.class);


    private MvcApplicationContext mvcContext = null;

    @Override
    public void contextInitialized(ServletContextEvent contextEvent) {
        try {
            mvcContext = new MvcApplicationContext(contextEvent);
            MvcContextApplicationHolder.setMvcApplicationContext(mvcContext);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }

    }

    @Override
    public void contextDestroyed(ServletContextEvent contextEvent) {

        //做一些资源清理
        MvcContextApplicationHolder.setMvcApplicationContext(null);
    }
}